#include "stm32f10x.h"                  // Device header
#include "Delay.h"

uint16_t Count = 0;//监控按键状态
void Key_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//选择PB11号引脚作为抢占中断引脚（按键引脚）
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_InitStructure);
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource11);
	
	EXTI_InitTypeDef EXTI_InitStructure;
	EXTI_InitStructure.EXTI_Line = EXTI_Line11;
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
	EXTI_Init(&EXTI_InitStructure);
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); 
	NVIC_InitTypeDef NVIC_InitStrucyure;
	NVIC_InitStrucyure.NVIC_IRQChannel = EXTI15_10_IRQn;
	NVIC_InitStrucyure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStrucyure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitStrucyure.NVIC_IRQChannelSubPriority = 1;
	NVIC_Init(&NVIC_InitStrucyure);
	
}

void EXTI15_10_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line11) == SET)
	{
		EXTI_ClearITPendingBit(EXTI_Line11);
		/*if(GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_2) == 0)
	{}*/if(Count == 0)//进入中断先判断一下状态：0代表紧急情况、 非0代表恢复正常状态
	    {
		GPIO_ResetBits(GPIOA,GPIO_Pin_2 | GPIO_Pin_8);
		GPIO_SetBits(GPIOA,GPIO_Pin_3 | GPIO_Pin_4);
		TIM_Cmd(TIM2,DISABLE);
	    Count++;
		}
		else
		{
		Count = 0;
		GPIO_SetBits(GPIOA,GPIO_Pin_8);
		TIM_Cmd(TIM2,ENABLE);
		
		}
	
	
	
}
}

		